package main

import (
	"fmt"
	"net/http"
)

// 处理请求

/**
获取请求头
*/
func headers(w http.ResponseWriter, r *http.Request) {
	h := r.Header      //获取请求头
	fmt.Fprintln(w, h) // 把请求头返回给客户端
}

/**
获取请求体
*/
func body(w http.ResponseWriter, r *http.Request) {
	len := r.ContentLength
	body := make([]byte, len)
	r.Body.Read(body)
	fmt.Fprintln(w, string(body))
}

func main40() {
	server := http.Server{
		Addr: "127.0.0.1:8089",
	}
	http.HandleFunc("/headers", headers)
	http.HandleFunc("/body", body)
	server.ListenAndServe()
}
